﻿
using System.Collections.ObjectModel;
using System.Web.Profile;
using System.Web.Security;
using FinalSilverlightProject.Web.Models;

namespace FinalSilverlightProject.Web.Services
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.ServiceModel.DomainServices.Hosting;
    using System.ServiceModel.DomainServices.Server;


    // TODO: Create methods containing your application logic.
    [EnableClientAccess]
    [RequiresAuthentication]
    [AdministratorAndCustomerRole]
    public class AdministratorService : DomainService
    {
        [Invoke(HasSideEffects = true)]
        public ObservableCollection<AdministratorEditRegistrationData> GetAllUsers()
        {
            MembershipUserCollection allUsers = Membership.GetAllUsers();
            var result = new ObservableCollection<AdministratorEditRegistrationData>();
            foreach (MembershipUser membershipUser in allUsers)
            {
                var profile = ProfileBase.Create(membershipUser.UserName, true);
                result.Add(new AdministratorEditRegistrationData()
                {
                    UserName = membershipUser.UserName,
                    Email = membershipUser.Email,
                    Role = Roles.GetRolesForUser(membershipUser.UserName)[0],

                    City = profile.GetPropertyValue("City").ToString(),
                    Country = profile.GetPropertyValue("Country").ToString(),
                    FirstName = profile.GetPropertyValue("FirstName").ToString(),
                    FriendlyName = profile.GetPropertyValue("FriendlyName").ToString(),
                    LastName = profile.GetPropertyValue("LastName").ToString(),
                    PostCode = profile.GetPropertyValue("PostCode").ToString(),
                    StreetAddress = profile.GetPropertyValue("StreetAddress").ToString(),
                    TelephoneNumber = profile.GetPropertyValue("TelephoneNumber").ToString()
                });
            }
            return result;
        }

    }
}


